import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import h5ProdEffectPlugin from 'uni-vite-plugin-h5-prod-effect';
import vueJsx from '@vitejs/plugin-vue-jsx';
import legacy from '@vitejs/plugin-legacy';
import tmuiCss from './src/tool/vitePlugs/tmuiCss';
import AutoImport from 'unplugin-auto-import/vite';
import { resolve } from 'path';
// import Components from 'unplugin-vue-components/vite'
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, 'src'),
      },
    ],
  },
  server: {
    // 选项写法
    proxy: {
      '/pag': {
        target: 'https://cdn.tmui.design',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api'),
      },
    },
  },
  plugins: [
    uni(),
    // 对h5 production环境打包时的特殊处理，否则uni-crazy-router在这个环境会异常
    h5ProdEffectPlugin(),
    vueJsx(),
    tmuiCss(),
    // legacy({
		// 	targets: [
		// 		"> 1%, last 1 version, ie >= 11",
		// 		"safari >= 10",
		// 		"Android > 39",
		// 		"Chrome >= 60",
		// 		"Safari >= 10.1",
		// 		"iOS >= 10.3",
		// 		"Firefox >= 54",
		// 		"Edge >= 15"
		// 	  ],
		// 	  additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
		// 	  renderLegacyChunks: true,
		// 	  polyfills: [
		// 		'es.symbol',
		// 		'es.array.filter',
		// 		'es.promise',
		// 		'es.promise.finally',
		// 		'es/map',
		// 		'es/set',
		// 		'es.array.for-each',
		// 		'es.object.define-properties',
		// 		'es.object.define-property',
		// 		'es.object.get-own-property-descriptor',
		// 		'es.object.get-own-property-descriptors',
		// 		'es.object.keys',
		// 		'es.object.to-string',
		// 		'web.dom-collections.for-each',
		// 		'esnext.global-this',
		// 		'esnext.string.match-all'
		// 	],
		// 	modernPolyfills: ["es.promise.finally"]
		// }),
    AutoImport({
      dts: false,
      // 这里除了引入 vue 以外还可以引入pinia、vue-router等，
      // 甚至你还可以使用自定义的配置规则，见 https://github.com/antfu/unplugin-auto-import#configuration
      imports: [
        'vue',
        'pinia',
        {
          '@/common/utils/http.ts': [
            // default imports
            ['default', '$http'],
          ],
          '@/api/index.ts': [
            // default imports
            ['default', '$api'],
          ],
          '@/router/index.ts': [
            // default imports
            ['default', '$router'],
          ],
          '@/store/index.ts': [
            // default imports
            ['default', '$store'],
          ],
        },
      ],
      // eslint报错解决
      eslintrc: {
        enabled: false, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
    }),
  ],
  build: {
    target: 'es2015',
  },
});
